|
| Contents | |
| Introduction |
Music Object is an abstraction layer that lies between a Beatnik Player that is instantiated on a page and the HTML page that wishes to control it. It becomes the author's means of communicating with a Beatnik Player instance. Instead of trying to 'speak' directly to the player instance, a Music Object instance is created and linked to the Beatnik Player instance. All communication is then sent to the Music Object instance and is then passed on in the correct manner to the Beatnik Player instance, which could be either the Beatnik Plug-in for Netscape or the Beatnik ActiveX control for Internet Explorer. The way in which one uses Music Object is described in more detail further on in this reference.
The Music Object API is a broad platform for the creation of interactive audio applications on the Web. The comprehensive list of interactive audio features of the Music Object API allows a wide variety of different sonified content to be created, ranging from very straightforward sonified banner ads, to more sophisticated sonified Web sites, and even more elaborate music applications and multimedia experiences.
Some of the types of applications that can be built using the Music Object API include...
There are some limitations to what the Music Object API can do. For example, because of the inherent latencies built into a browser's scripting layer, it wouldn't really be feasible to build a Web-based professional grade synthesizer or music sequencer using the Music Object API.
To see some great examples of the Music Object API in action, check out the Beatnik Showcase.
Within the Music Object code, the connection to the Beatnik Plug-in is made through Netscape's LiveConnect technology, or to the Beatnik ActiveX control through Microsoft's ActiveX scripting. It is not necessary for authors to fully understand this mechanism as this is made fairly transparent through the use of the Music Object code.
Music Object is a JavaScript class that is defined in the JavaScript file called "music-object.js". This JavaScript file is sourced into the HTML document that is to contain Beatnik interactive authoring using the statement <SCRIPT SRC="music-object.js"></SCRIPT>
The Music Object abstraction layer performs some very vital functions, without which, authoring for Beatnik would be cumbersome.
MusicObject acts as a wrapper and protection layer around the Beatnik Plug-in's LiveConnect methods. Once a Music Object instance has been created, it is possible in one's authoring to call that Music Object instance's methods directly without having to worry about whether the player is fully instantiated and ready yet. It alleviates the peculiar symptoms associated with LiveConnect JavaScript authoring.
There are a few fundamental differences between LiveConnect scripting and ActiveX scripting that would make programming interactive sonified Web pages more complex if it was left to the author to work around these differences. By managing these differences in the "music-object.js" file (which is sourced into the author's HTML page), the author not only does not need to understand and deal with these differences, but also does not need to have their JavaScript sonification code cluttered by the code that manages the 'wiring' to the player.
The Music Object API extends the Beatnik Player's existing API and offers a few very useful sonification methods. These very methods may make their way into future versions of the player's LiveConnect authoring API.
To get the "music-object.js" JavaScript file, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object.js" into an appropriate directory of the local copy of your Web site.
In order to set up an HTML page with the necessary framework for Beatnik interactive authoring, you should follow the guidelines in the section that follows, Starting to use Music Object
YES. You can create as many Music Object instances as you like on the same HTML page. Bear in mind that for each Music Object instance you are expected to embed a Beatnik Player into the page. While there is also no strict limit on the number of Beatnik Player instances living on the same HTML page, there is a maximum limit of sixteen instances that can be playing at the same time (for some older versions of the Beatnik Player, the limit may be eight). If you are going to create many Music Object instances with accompanying players, you should be aware that for each Music Object instance there is a modest minimum amount of memory that is needed on the user's system. The same applies to each Beatnik Player that accompanies a Music Object instance. In addition, when a Beatnik Player loads in its music or audio file, that file must then be contained in the user's memory.
So, while there are no forced limitations on the number of Music Object instances and Beatnik Player instances, you should be careful not to author pages that make such heavy demands on the user's memory resources that the pages then become sluggish and unbearable to use.
For more information, see the section Creating Multiple Instances.
The Beatnik Player offers extensive support for realtime control, offered to authors through the Music Object authoring API. Authors can design startlingly interactive Web pages, demonstrated very effectively in the Beatnik Web site's Showcase area, as well as the Sample Code & Examples contained in this documentation.
To be able to fully unleash the interactive capabilities of Beatnik, you should have a healthy understanding of the JavaScript language. This documentation only assumes knowledge of JavaScript 1.1 and none of the tutorials, sample code, or examples currently make use of the more powerful features of JavaScript 1.2. Browsers that support this version of JavaScript are not yet considered universal enough.
You should setup a bookmark to Netscape's on-line JavaScript documentation to use as a reference as you author using JavaScript.
| What's New In the Latest Version of Music Object? |
IMPORTANT : All the information in this documentation reflects the very latest version of the Music Object API. If you are not using the latest version in your sonification, then you should immediately update your content to use the latest version before using the reference information contained inside this documentation in your authoring.
The Beatnik Music Object Documentation contains a Music Object Version History, where you will be able to find out about the new features and possible issues with the most recent version of the Music Object API, as well as helpful guidelines for updating your sonified content from older Music Object versions.
| Starting to use Music Object |
The following sections will take you step-by-step through the process of setting up a very simple example sonified page. If you observe the basic principles outlined in the sections below, you should be able to start creating your own sonified HTML pages or adding sonification to existing pages.
The core Music Object API is implemented in the "music-object.js" JavaScript file. The first thing you need to do is to make sure that this file is available on your Web site. To get the file, simply right-click on this link (click-and-hold for Mac users). Then, from the menu that pops up, select the 'Save Link As...' or 'Save Target As...' option and save the file as "music-object.js" into the folder that contains the local copy of your Web site.
Once the "music-object.js" file has been copied into your Web site folder, you then need to source the file into the Web page you wish to sonify. This is down using the HTML SCRIPT tag, as follows...
<HTML><HEAD><TITLE>My Sonified Page</TITLE></HEAD>
<BODY>
<SCRIPT SRC="music-object.js"></SCRIPT>
</BODY></HTML>
|
The SCRIPT tag that sources in the "music-object.js" file is highlighted in the above sample code segment.
|
Now that the "music-object.js" file has been sourced into the HTML page, you can create a Music Object instance by adding JavaScript code as follows...
<HTML><HEAD><TITLE>My Sonified Page</TITLE></HEAD>
<BODY>
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
notePlayer = new Music ();
// --></SCRIPT>
</BODY></HTML>
|
The code that creates the Music Object instance notePlayer is highlighted in the above sample code segment. Notice that a separate SCRIPT tag has been created to contain this JavaScript code. It is not possible to place this code inside the same SCRIPT tag that sources in the "music-object.js" file. If you were to do this, your code may fail in some browsers.
There is an alternative syntax for creating Music Object instances, where you specify the name of the Music Object instance you wish to create as a string parameter in the call to the Music constructor, as follows...
<HTML><HEAD><TITLE>My Sonified Page</TITLE></HEAD>
<BODY>
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
new Music ('notePlayer');
// --></SCRIPT>
</BODY></HTML>
|
Although both of the above approaches are valid, the first approach is the preferred one. You will see this approach used in most sample code examples throughout the documentation. Don't be alarmed, however, if you see the second approach in sonification code that you receive from online discussion forums or from other online Web sonification resources.
The music playback capability of the Music Object API is provided by a player which is implemented in native code - not in JavaScript code. This player comes in the form of a browser add-on component: a plug-in for Netscape browsers and an ActiveX control for Microsoft Internet Explorer. Now, in order for a Music Object instance to be operational and have the ability to play music and audio, a player instance must be created that is linked to the Music Object instance. This is done using one of the various embedding methods that are provided by the Music Object API.
In this example, we will use the stubEmbed instance method to embed the Music Object instance's player, since this method provides us a convenient way to embed a player instance that is correctly set up for playing musical notes. The code is as follows...
<HTML><HEAD><TITLE>My Sonified Page</TITLE></HEAD>
<BODY>
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
notePlayer = new Music ();
notePlayer.stubEmbed ('stub.rmf');
// --></SCRIPT>
</BODY></HTML>
|
The code that embeds the Music Object instance's player is highlighted in the above sample code segment. The file "stub.rmf" is a special type of RMF file that is silent when it is played, because it contains no musical note data. This allows the file to be continuously playing, without actually playing anything other than the musical notes that are triggered using the note playing methods of the Music Object API.
|
Now that your code is sourcing in the "music-object.js" file, creating a Music Object instance, and embedding the Music Object instance's player, your instance should be ready for action and you can now add some code to the page to test that the Music Object instance is operational. For illustration, we will add some code to play musical notes when the user mouses over links.
<HTML><HEAD><TITLE>My Sonified Page</TITLE></HEAD>
<BODY>
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT LANGUAGE=JavaScript><!-- //
notePlayer = new Music ();
notePlayer.stubEmbed ('stub.rmf');
// --></SCRIPT>
<A
HREF="some-page1.html"
ONMOUSEOVER="notePlayer.playNote (1,0,128+85,60,127,1000)"
>
Some Link 1
</A>
<BR>
<A
HREF="some-page2.html"
ONMOUSEOVER="notePlayer.playNote (1,0,128+75,60,127,1000)"
>
Some Link 2
</A>
<BR>
<A
HREF="some-page3.html"
ONMOUSEOVER="notePlayer.playNote (1,1,128+46,79,127,1000)"
>
Some Link 3
</A>
<BR>
</BODY></HTML>
|
The code that has been added for creating links with mouseover sounds is highlighted in the above sample code segment. You will notice that the A tag for each link contains an ONMOUSEOVER attribute. This attribute is used to specify JavaScript code that should be executed when the user mouses over a link. In this example, the code specified in the ONMOUSEOVER attribute is a call to the playNote method of the notePlayer Music Object instance.
The example is now complete. You can use this very basic example as a template for creating other sonified pages, or just as a reference when adding sonification to existing HTML pages.
The above example assumed that the "music-object.js" file was copied into the Web site's folder at the same level as the sonified HTML page. You could alternatively put the "music-object.js" file into a dedicated "javascript" folder. This can be a good practice when you start using some of the many Music Object extensions in order to further enhance the sonification of your Web pages. Each Music Object extension is implemented in its own separate JavaScript file, and placing all the JavaScript files in a dedicated folder can help to better organize the media used by your Web site.
If you decide to place all JavaScript files into a dedicated "javascript" folder, then you must make sure to source in the files using the correct path to the files (including specifying the folder that the files are in). So, in the above example, the SCRIPT tag that sourced in the "music-object.js" file would have to be modified to...
<SCRIPT SRC="javascript/music-object.js"></SCRIPT>
|
The above example assumed that the "stub.rmf" file was copied into the Web site's folder at the same level as the sonified HTML page. You could alternatively put the "stub.rmf" file into a dedicated "music" folder. This can be a good practice when you start using lots of different music files in the sonification of your Web pages. Placing all the music files in a dedicated folder can help to better organize the media used by your Web site.
If you decide to place all music files into a dedicated "music" folder, then you must make sure to specify the correct path to the files (including specifying the folder that the files are in) when making calls to the embedding methods of the Music Object API. So, in the above example, the stubEmbed method call that embedded the Music Object instance's player would have to be modified to...
notePlayer.stubEmbed ('music/stub.rmf');
|
Before you upload your sonified Web pages to test them online, you should make sure that your Web server has the correct MIME type set up for JavaScript files. JavaScript files should always have the file extension ".js" and this file extension should be mapped to the MIME type "application/x-javascript". If you do not have this MIME type configured on your server, your sonified pages may not work correctly in certain browsers. They may work locally while you are authoring and previewing them, but they may not work when visitors try to view them from your Web site. Refer to Dealing with MIME Types for further information.
| Creating Multiple Instances |
It is only possible to play one file at a time through a player instance. So, for example, it is not possible to fade one piece of music out while another piece fades in, using just one player instance. In order to achieve this effect, one would need to use two different player instances, with one playing the file that is fading out and the other playing the file that is fading in. To understand this, it is best to think of the Beatnik Player as though it were a typical CD player in a home stereo system. In order to put a new CD in, it is necessary to take the currently playing CD out first. You can't fade between the two CD's using just one CD player.
Now, it is possible to have an almost unlimited number of player instances on any HTML page, with as many as 16 players actually playing music at any given time. So, by adding a little bit of scripting wizardry, it should be no problem to use two player instances to achieve a cross-fade effect between two music files. And, when you start using 2 or more instances you can really start to do some sophisticated sonification.
Because player instances need to be embedded into the HTML page, it is not possible to dynamically add more player instances after the page has already loaded. So, you need to assess upfront how many instances you might need for your page sonification and then create that many instances. It is possible to embed as many player instances as you want, with some instances that are not doing anything initially and are just "waiting in the wings". Creating multiple instances is quite easy, and just extends on the principles that were demonstrated in the previous section Starting to use Music Object.
In the example below, we are creating two instances: one instance will play musical notes to sonify navigation links, and the other instance will play music in the background...
| |
<HTML><HEAD><TITLE>Multiple Instances Template</TITLE></HEAD> <BODY> <SCRIPT SRC="music-object.js"></SCRIPT> <SCRIPT LANGUAGE=JavaScript><!-- // notePlayer = new Music (); musicPlayer = new Music (); // --></SCRIPT> <A HREF="some-page1.html" ONMOUSEOVER="notePlayer.playNote (1,0,128+85,60,127,1000)" > Some Link 1 </A> <BR> <A HREF="some-page2.html" ONMOUSEOVER="notePlayer.playNote (1,0,128+75,60,127,1000)" > Some Link 2 </A> <BR> <A HREF="some-page3.html" ONMOUSEOVER="notePlayer.playNote (1,1,128+46,79,127,1000)" > Some Link 3 </A> <BR> <SCRIPT LANGUAGE=JavaScript><!-- // notePlayer.stubEmbed ('stub.rmf'); musicPlayer.magicEmbed ( 'SRC="background-music.rmf" ' + 'WIDTH=0 ' + 'HEIGHT=0 ' + 'HIDDEN ' + 'AUTOSTART=TRUE ' + 'VOLUME=70' ); // --></SCRIPT> </BODY></HTML> |
The text that is highlighted in the above source code listing represents the code that deals specifically with creating multiple instances (two in this example). Of course, there's nothing to say that you couldn't use 3, 4, or even more instances for your page sonification, depending on how complex the sonification is to be. The general rule to remember is that for each Music Object instance you create, you should also embed a corresponding player instance using one of the embedding methods provided by the Music Object API.
| Methods and Properties |
The Music Object API can be broken down into four main functional categories: instance methods, instance properties, static methods, and static properties. The diagram below roughly illustrates the relationship between these functional categories.
In the above diagram, the top container represents the Music Object class, which contains the static methods and static properties that are global to any HTML page that is authored using the Music Object API. Static methods and static properties are referenced from the Music object, as in the statement
Below the Music Object container, several containers represent multiple Music Object instances that have been created. Each instance maintains its own state, and this state can be accessed using the instance methods and instance properties. Instance methods and instance properties are referenced from the Music Object instance name. For example, if an instance was created named "myMusicObject", then the statement
Now, let's take a look at each functional category in further detail...
For a full list of all the instance methods, see the Instance Methods reference section.
Instance properties are specific to Music Object instances, as opposed to the shared global audio engine. Each Music Object instance maintains its own state, so the statement
For a full list of all the instance properties, see the Instance Properties reference section.
For a full list of all the static methods, see the Static Methods reference section.
For a full list of all the static properties, see the Static Properties reference section.
| File Types and Functionality |
Beyond the methods that allow control over general Music Object instance state, the core Music Object API offers a healthy share of methods that facilitate playback control and obtaining state information for a Music Object instance's currently loaded file. The Music Object API offers only one set of methods and properties, regardless of the type of file that is currently loaded into an instance. Because the Beatnik Player is capable of playing several audio and music file formats - including RMF, MIDI, WAV, AIFF, and AU - there can be situations where a certain method or property will have no meaning for the file that is currently loaded into the player. For example, if the player had a WAV file loaded, then calling the setProgram method would not be appropriate, since this method only has meaning for RMF and MIDI files.
When a particular method has no meaning for the file type that is loaded into the player, then calling that method will simply not do anything - it will not produce a JavaScript error. If it is a method that returns state about the instance, and the method has no meaning for the file type that is loaded into the player, then the method will return meaningless data. An example of this would be calling the getProgram method for a Music Object instance that had an AIFF file loaded. It is up to you, as a content author, to design your sonification code to be aware of the types of files that are loaded into Music Object instances and to only call methods that are appropriate to those media types.
There are three categories of file types that the Music Object API addresses...
To understand how the playback control API features are broken up into different groups based upon file type, consider the table below. In this table, it is shown that the API provided for the control of RMF file playback is a superset of the API provided for the control of MIDI file playback, and the API provided for the control of MIDI file playback is a superset of the API provided for the control of linear digital audio file playback (WAV, AIFF, AU).
| Music Object API Reserved Words |
To avoid conflicts in your code and possible unexplained failings in your programming, you should be mindful of the reserved words that are defined in the Music Object API. You should avoid using these reserved words, since any variables or functions that you name the same as identifier names that are defined in the Music Object API will likely cause havoc.
The majority of functions and variable names in the Music Object API are prefixed with "mo_", while a few are prefixed with "Music_". This dramatically reduces the likelihood that Music Object identifier names could encroach on your own identifier names. To be safe, always ensure that your sonification code does not define identifiers that begin with "mo_" or "Music_", unless you are specifically writing Music Object extensions.
In addition, the names "Music" and "musicObject" are reserved for the object constructor that lets you define new Music Object instances. You should, of course, never use these names for your own variables or functions, or you will not be able to use the Music Object API at all.
| Layers of the Music Object API |
The Music Object API is made up of several layers, much like the layers of an onion. At the core are the foundation layers upon which all the layers moving outwards are built. Typically, each new layer that is added builds upon previous layers and adds new capabilities. The diagram below illustrates how all the various Music Object layers relate to each other...
The full Music Object API is made up of the following layers, which are discussed in more detail further below...
The core Music Object API, which is implemented in the "music-object.js" JavaScript file, is typically all that is needed in most sonification jobs. None of the further layers are required, but may be used optionally depending on the needs of a sonification job.
The core Music Object API is comprised of three core components, which are available also in the form of separate JavaScript files. Each core component provides a certain subset of the capabilities of the core Music Object API ("music-object.js"), so when using the separate core component JavaScript files, the core components may be combined together in different combinations, depending on the needs of the sonification job at hand. When all three core components are sourced into a page as separate JavaScript files, this has the same effect as sourcing in the standard "music-object.js" file.
So, in other words, the following code...
<SCRIPT SRC="music-object-c-basic.js"></SCRIPT> <SCRIPT SRC="music-object-c-advanced.js"></SCRIPT> <SCRIPT SRC="music-object-c-compatibility.js"></SCRIPT> |
...has the same effect as just...
<SCRIPT SRC="music-object.js"></SCRIPT> |
Dividing the core Music Object API into logical core components provides authors with a way to potentially reduce the load time of sonified pages. For instance, if a particular sonified Web site was only targeted to an audience that already had the Beatnik Player installed, or if a gateway page for the site ensured that all those who entered already had the Player installed, then using the compatibility core component in sonified pages of the site would be unnecessary. So, one could then use only the basic and advanced core components. For convenience, core components can also be combined together into a Music Object Suite, as per the specific needs of any given sonification job.
For more information and for guidelines on using the core components, see the section Music Object Core Components.
The optional language modules allow you to customize the prompts that pop up as a result of the user not having the Beatnik Player installed, so that they appear in a language appropriate to the Web content you are sonifying. This applies also to the prompts that appear when the sonified content requires a version of the Beatnik Player higher than the Player that is installed on the user's system, and also the prompt that appears for Netscape Navigator users who have Java disabled.
Using a language module is easy. Simply source in the desired language module's JavaScript file after sourcing in the core Music Object API, as follows...
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-l-spanish.js"></SCRIPT>
|
For more information and for guidelines on using language modules, see the section Music Object Language Modules.
Optional extensions allow you to add further capabilities to the Music Object API, and are available as JavaScript files. Different extensions are geared towards different types of sonification needs. For example, "Music Object Extension - Groups" is ideal for making remix interfaces easier to code, and "Music Object Extension - Dynamic" is ideal for making sonified Web pages remain fresh and entertaining.
Extensions offer several key benefits...
Using extensions is easy. Simply source in the desired extensions' JavaScript files after sourcing in the core Music Object API. In the following example, "Music Object Extension - Groups" and "Music Object Extension - Fades" are being used...
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-groups.js"></SCRIPT>
<SCRIPT SRC="music-object-x-fades.js"></SCRIPT>
|
For more information and for guidelines on using extensions, see the section Music Object Extensions.
Unlike extensions, the optional patches do not add new features or capabilities to the Music Object API, but are intended to fix certain problems that may arise from browser compatibility issues or changes that occur between different versions of the Music Object API. For example, Music Object Patch - Pre 3.3.0 is designed to help authors transition from Music Object version 3.2.x to version 3.3.0 without having to change any sonification scripting, even though changes were made to the API between version 3.2.x and version 3.3.0.
Patches offer several key benefits...
Using patches is easy. Simply source in the desired patches' JavaScript files after sourcing in the core Music Object API. In the following example, "Music Object Patch - Navigator 4.04 Bug" is being used...
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-p-nav404.js"></SCRIPT>
|
For more information and for guidelines on using patches, see the section Music Object Patches.
| Making a Custom Music Object Suite |
If you find that certain Music Object extensions or patches are of great value to you in your general sonification, or even just to a specific site you're working on, you may elect to create a custom Music Object suite so that you're not sourcing in several JavaScript files on every sonified Web page. There are benefits to creating a custom Music Object suite, and there are also inherent risks...
|
Creating your own custom Music Object suite is quite easy. You should decide which extensions and patch modules you would like to include in the suite and then simply copy-and-paste these modules into a newly created text file, using your text editor of choice. Be sure to paste the contents of the "music-object.js" file at the top of this document, with all the extension and patch modules pasted in below. You should apply the same principles of ordering as you would when sourcing in the extension and patch modules as discrete JavaScript files.
To be 100% certain of the order in which extensions and patches should be pasted in, consult the documentation for the extensions or patches you plan to use to find out what their dependencies are. As a simple rule, if an extension / patch depends on another extension / patch, then that required extension / patch should be pasted into the suite before the extension / patch that depends on it.